<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>生产订单工序状态查询报表</title>
  <style>
    .el-date-editor--daterange.el-input,
    .el-date-editor--daterange.el-input__inner,
    .el-date-editor--timerange.el-input,
    .el-date-editor--timerange.el-input__inner {
      width: 300px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'生产订单工序状态查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable
            @change="factorySelectChange">
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="plannedcompletiondate" label="订单计划完成时间:">
          <el-date-picker v-model="queryInfo.plannedcompletiondate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="主制工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择主制工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
              :value="i.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="排产计划完成时间:">
          <el-date-picker v-model="queryInfo.plannedfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="实际完工时间:">
          <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="实际开始时间:">
          <el-date-picker v-model="queryInfo.dispatchdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="排产操作时间:">
          <el-date-picker v-model="queryInfo.stepplancreatedate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="排产人:">
          <el-select v-model="queryInfo.stepplancreateemployeeid" placeholder="请选择" clearable filterable
            style="width:140px;">
            <el-option v-for="e in planerList" :key="e.employeeid" :label="e.fullname" :value="e.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开卡人:">
          <el-select v-model="queryInfo.startemployeeid" placeholder="请选择" clearable filterable style="width:140px;">
            <el-option v-for="e in starterList" :key="e.employeeid" :label="e.fullname" :value="e.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主制分厂是否排产:">
          <el-select v-model="queryInfo.isplan" placeholder="请选择" clearable filterable style="width:140px;">
            <el-option :key="'已排产'" :label="'已排产'" :value="'已排产'"></el-option>
            <el-option :key="'未排产'" :label="'未排产'" :value="'未排产'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工序状态:">
          <el-select v-model="queryInfo.stepstatus" placeholder="请选择" clearable filterable style="width:140px;">
            <el-option :key="'未完成'" :label="'未完成'" :value="'未完成'"></el-option>
            <el-option :key="'已完成'" :label="'已完成'" :value="'已完成'"></el-option>
            <el-option :key="'完工入库'" :label="'完工入库'" :value="'完工入库'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="排产状态:">
          <el-select v-model="queryInfo.stepplanstatus" placeholder="请选择" clearable filterable style="width:140px;">
            <el-option :key="'主制分厂未排产'" :label="'主制分厂未排产'" :value="'主制分厂未排产'"></el-option>
            <el-option :key="'承制分厂未排产'" :label="'承制分厂未排产'" :value="'承制分厂未排产'"></el-option>
            <el-option :key="'按时完成'" :label="'按时完成'" :value="'按时完成'"></el-option>
            <el-option :key="'超期完成'" :label="'超期完成'" :value="'超期完成'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handlerSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>

        <el-form-item label="排产零件数:">
          <el-tag>{{computeData.productCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期工序数:">
          <el-tag type="warning">{{computeData.delaySpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="完工工序数:">
          <el-tag type="success">{{computeData.finishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="按时完工数:">
          <el-tag type="success">{{computeData.intimeFinishCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期完工数:">
          <el-tag type="warning">{{computeData.delayfinishedSum}}</el-tag>
        </el-form-item>

        <el-form-item label="未完工序数:">
          <el-tag type="danger">{{computeData.notFinishCount}}</el-tag>
        </el-form-item>

        <el-form-item label="完成率:">
          <el-tag type="success">{{computeData.finishRate}}%</el-tag>
        </el-form-item>

        <el-form-item label="按时完成率:">
          <el-tag type="success">{{computeData.intimeFinishRate}}%</el-tag>
        </el-form-item>

        <el-form-item label="超期完成率:">
          <el-tag type="warning">{{computeData.delayFinishRate}}%</el-tag>
        </el-form-item>

        <el-form-item label="未完成率:">
          <el-tag type="danger">{{computeData.notFinishRate}}%</el-tag>
        </el-form-item>

        <el-form-item label="总工序数:">
          <el-tag>{{total}}</el-tag>
        </el-form-item>

        <el-form-item label="排产工序数:">
          <el-tag>{{computeData.specCount}}</el-tag>
        </el-form-item>

        <el-form-item label="未排产工序数:">
          <el-tag>{{total-computeData.specCount}}</el-tag>
        </el-form-item>

        <el-form-item label="排产率:">
          <el-tag>{{((computeData.specCount / total) * 100).toFixed(2)}}%</el-tag>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="订单数" prop="mfgorderqty" width="60"></el-table-column>
        <el-table-column label="机型" prop="familylistnames" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次数" prop="qty" width="60px"></el-table-column>
        <el-table-column label="工序" prop="workflowstepname" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="工序所属分厂" prop="specfactoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="是否转工序" prop="spectype" width="60"></el-table-column>
        <el-table-column label="是否排产" prop="isplan" width="80">
          <template slot-scope="scope">
            <el-tag :type="scope.row.isplan === '已排产' ? 'success':'danger'">{{scope.row.isplan}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="订单计划完成时间" prop="plannedcompletiondate" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="排产计划完成时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际完成时间" prop="checkdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="工序状态" prop="stepstatus" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.stepstatus === '完工入库'" type="info">{{scope.row.stepstatus}}</el-tag>
            <el-tag v-else-if="scope.row.stepstatus === '已完成'" type="success">{{scope.row.stepstatus}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.stepstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="排产状态" prop="finishstatus" width="140">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.finishstatus === '主制分厂未排产' || scope.row.finishstatus === '承制分厂未排产'">
              {{scope.row.finishstatus}}
            </el-tag>
            <el-tag v-else-if="scope.row.finishstatus === '按时完成'" type="success">{{scope.row.finishstatus}}</el-tag>
            <el-tag v-else type="warning">{{scope.row.finishstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="实际开始时间" prop="dispatchdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="开卡人" prop="containerstartemp" width="70" show-overflow-tooltip></el-table-column>
        <el-table-column label="排产人" prop="stepplanemp" width="70" show-overflow-tooltip></el-table-column>
        <el-table-column label="排产操作时间" prop="stepplancreatedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="责任工区" prop="workcentername" width="100" show-overflow-tooltip></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[15,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getFactory, getProductFamily, getFactoryUsersByRoleName, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryid: '',
          workcenterid: '',
          productfamilyname: '',
          productname: '',
          plannedfinishdate: '',
          checkdate: '',
          dispatchdate: '',
          stepplancreatedate: '',
          mfgordername: '',
          stepplancreateemployeeid: '',
          startemployeeid: '',
          isplan: '',//主制分厂是否排产
          stepstatus: '',//工序完工状态
          stepplanstatus: '',//工序排产状态
          containername: '',
          plannedcompletiondate: '',
          currentPage: 1,//当前页
          pageSize: 15//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        factoryList: [],
        workcenterList: [],
        productFamilyList: [],
        planerList: [],//排产人
        starterList: [],//开卡人
        dataList: [],
        computeData: {},
        // 表单验证
        rules: {
          factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }],
          plannedcompletiondate: [{ required: true, message: '订单计划完成时间不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback })
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        async factorySelectChange(factoryid) {
          this.queryInfo.workcenterid = null;
          if (factoryid) {
            this.workcenterList = await getWorkcenterList({ factoryid });
            this.starterList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
            this.planerList = await getFactoryUsersByRoleName({ factoryid, rolename: '工区长|班组长' });
          }
        },
        handlerSearch() {
          const valid = this.validate();
          if (!valid) {
            return this.$message.error('必填项不能为空');
          } else {
            this.getData();
            this.getCompute();
          }
        },
        validate() {
          let isvalid = false;
          this.$refs['queryInfoRef'].validate(async valid => isvalid = valid);
          return isvalid;
        },
        //查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/MfgorderStepStatusReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 查询汇总数据
        async getCompute() {
          const { data: { data, meta, total } } = await axios.post('../handler/report/MfgorderStepStatusReport.ashx?action=getCompute', {
            type: 'getCompute',
            ...this.queryInfo
          })
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.computeData = data[0];
        },
        //导出excel
        async getExportExcel() {
          const valid = this.validate();
          if (!valid) {
            return this.$message.error('必填项不能为空');
          }
          const config = {
            url: '../handler/report/MfgorderStepStatusReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          const valid = this.validate();
          if (!valid) {
            return this.$message.error('必填项不能为空');
          }
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          const valid = this.validate();
          if (!valid) {
            return this.$message.error('必填项不能为空');
          }
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.productFamilyList = await getProductFamily();
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
        this.starterList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
        this.planerList = await getFactoryUsersByRoleName({ factoryid, rolename: '工区长|班组长' });
        const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD')
        const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD')
        this.queryInfo.plannedcompletiondate = [monday, sunday]
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>